/**
 * 
 */
package com.obaamilos.msstore;

import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.tdb.TDBFactory;
import com.hp.hpl.jena.update.GraphStore;
import com.hp.hpl.jena.update.GraphStoreFactory;
import com.hp.hpl.jena.update.UpdateExecutionFactory;
import com.hp.hpl.jena.update.UpdateFactory;
import com.hp.hpl.jena.update.UpdateProcessor;
import com.hp.hpl.jena.update.UpdateRequest;

/**
 * @author Pedro R. Oliveira
 *
 */
public class UpdateSparql {

	private String updateString;
	private String diretorio;
    private String result;

	public void run() {
        try {
            Dataset dataset = TDBFactory.createDataset(diretorio) ;

            GraphStore graphStore = GraphStoreFactory.create(dataset) ;
            UpdateRequest request = UpdateFactory.create(updateString) ;
            UpdateProcessor proc = UpdateExecutionFactory.create(request, graphStore) ;
            
            proc.execute() ;
            
            graphStore.finishRequest();
            dataset.close() ;
        } catch (Exception e) {

        	result = "Ocorreu um erro ao atualizar: " + e.getMessage();

        }
        
        result = "OK";
    }

    public String getUpdateString() {
        return updateString;
    }

    public void setUpdateString(String updateString) {
        this.updateString = updateString;
    }

    public String getDiretorio() {
		return diretorio;
	}

	public void setDiretorio(String diretorio) {
		this.diretorio = diretorio;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}
}
